<?php
 
        session_start ();
        Header("Content-type: image/PNG"); 
        //创建图片
        $im=imagecreate($x=118,$y=45);
        $bg=imagecolorallocate($im,rand(50,200),rand(0,155),rand(0,155)); //创建背景色
        $fontColor=imageColorAllocate ($im,255,255,255); //字体颜色  
		
        //干扰点
        for ($i=0;$i<80;$i++){
                imagesetpixel($im,rand(0,$x),rand(0,$y),$fontColor);
        }
	    
		 //干扰线
        for ($i=0;$i<6;$i++){
                $lineColor= imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
                imageline ($im,rand(0,$x),0,rand(0,$x),$y,$lineColor);
        }
		
		//将随机数画到边框上
		 $char=array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9');
		 $code = "";  
		 for($i = 0; $i <4; $i++) {  
		    $j=rand(0,35);
            $code .=$char[$j];
         }  
		 $_SESSION["yzm"]=$code;
		 //将数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
		 imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
		  
         $strx = rand(3, 10);  
         for ($i = 0; $i <4; $i++) {  
			$strpos = rand(1, 6);  
			imagestring($im,5,$strx,$strpos,substr($code, $i, 1),$fontColor);  
			$strx += rand(8, 12);  
		 }  
		 
         imagepng($im); //输出图形
         imagedestroy($im);//将资源全部清空   
?>